
define(['vue','config','common'],function(Vue,config,utils){
	'use strict';

	var EnjoyPointsOperateView = new Vue({
		el:'#app',
		data:{
			xValueTotal:0,
			userTypeId:'',
			submitBtn: false
		},
		created:function(){	
			var _this = this;
			_this.userTypeId =utils.getData('userTypeId');
			utils.ajax(utils.getWebUrl('user/personal'),null,'POST',function(res){
		   	 	//_this.xValueTotal = res.data.integral;   //享积分
		   	 	var xValueTotal = res.data.integral;
		   	 	if(xValueTotal == null){
		   	 		_this.xValueTotal = 0;
		   	 	}else{
		   	 		_this.xValueTotal = res.data.integral;
		   	 	}
		   });
		},

		methods:{
			back:function(){
				console.log(1)
				if(this.userTypeId == 5){
					window.location.href='shopInfo.html';
				}else{
					window.location.href='userInfo.html';
				}
			},
			save:function(){
				var _this = this;
				var integral = $("#integral").val();
				//console.log(integral+"=========="+_this.xValueTotal);
				//console.log(integral%100);
				if($.trim(integral) === "" || integral==0){
                    utils.appAlert('要兑换的享积分不能为空',function(){
                    	$('#integral').focus();
                    });
                    return;
				}
				if(integral>_this.xValueTotal){
                    utils.appAlert('您可以用的享积分不足',function(){
                    	$('#integral').focus();
                    });
                    return;
				}

				if(integral%100 && integral!=0){
					utils.appAlert('享积分满100才可兑换，且必须是100的倍数！');
					return;	
				}
				if (_this.submitBtn) {
					return;
				}

				var data = {
					integral: integral
				}
				_this.submitBtn = true;
				utils.ajax(utils.getWebUrl('integral/toBalance'),data,'POST',function(res){
					if(res.code=="10000"){
						utils.appAlert('您已兑换'+integral+'，扣除5%的手续费后，实际到账'+integral*0.95+'',function(){
							_this.xValueTotal -= integral;
							_this.submitBtn = false;
							$("#integral").val('')
						},'继续操作',function(){
							var userTypeId = utils.getData('userTypeId');

							if(userTypeId == 4){
								window.location.href='userInfo.html';
							}else{
								window.location.href='shopInfo.html';
							}
						},'返回首页','成功');
					}
					
				},null,null,null,function(res){
					_this.submitBtn = false;
					utils.appAlert(res.msg);
				})
			}
		}
		
	});


	return EnjoyPointsOperateView
});
